<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
  <th:block th:include="include :: header('回复并审核电话工单')"/>
  <style>
    label {
      font-weight: bold;
    }

    @font-face {
      font-family: 'huawen';
      src: url("/fonts/huawen.woff2");
    }
  </style>
</head>

<body style="background-color: #F4F6FA;font-size: 13px;font-family:'huawen' ;font-weight: bold">
<div class="main-content" style="margin: 0;padding: 0">

  <form id="form-user-add" th:object="${sendBackEty}" class="form-horizontal" style="background-color: #F4F6FA">
    <input type="hidden" th:field="*{wfId}"/>
    <input type="hidden" th:field="*{pkId}"/>
    <input type="hidden" th:field="*{sortCode}"/>
    <input type="hidden" th:field="*{sdeptName}"/>
    <input type="hidden" th:field="*{sdeptId}"/>
    <input type="hidden" id="crtUserRole" th:value="${user.roles.get(0).roleId}"/>
    <input type="hidden" name="crtStepId" id="crtStepId"/>
    <input type="hidden" name="crtStepName" id="crtStepName"/>

    <input type="hidden" id="setProId" th:value="${workForm.setProId}"/>
    <input type="hidden" name="backState" id="backState" th:value="*{backState}"/>
    <input type="hidden" name="opinion" id="opinion">
    <input type="hidden" name="txtReason" id="txtReason">

    <div class="col-sm-12" style="display:flex;">
      <div class="entering-page" style="overflow:hidden;">
        <!--    回复电话工单    -->
        <div class="col-sm-12 tltieBoder">
          <div class="blueBorder"></div>
          <h4 style="margin:0 0 0 10px">回复信息</h4>
        </div>
        <!--    隐藏内容       -->
        <div style="display: none">
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd">建议办结及理由：</label>
              <div class="col-sm-6">
                                <textarea th:field="*{reason}" maxlength="1000"
                                          class="form-control"
                                          cols="60"
                                          rows="3"></textarea>
              </div>
            </div>

          </div>
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd" style="color: red">执行处(科)室：</label>
              <div class="col-sm-6">
                <input th:field="*{bdutyDept}" type="text" class="form-control">
              </div>
            </div>
          </div>
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd" style="color: red">联系电话：</label>
              <div class="col-sm-6">
                <input th:field="*{bdutyTel}" type="text" class="form-control">
              </div>
            </div>
          </div>
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd">回复人：</label>
              <div class="col-sm-6">
                <input name="buserName" th:value="${user.userName}" type="text" class="form-control">
                <input type="hidden" name="buserNo" th:value="${user.userNo}"/>
              </div>
            </div>
          </div>
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd">回复时间：</label>
              <div class="col-sm-6">
                <input name="backTime" th:value="${nowTime}" type="text" class="form-control">
              </div>
            </div>
          </div>
          <div class="col-sm-12">
            <div class="form-group">
              <label class="col-sm-3 control-label entering-pd">备注：</label>
              <div class="col-sm-6">
                <input th:field="*{backRemark}" type="text" class="form-control">
              </div>
            </div>
          </div>
        </div>
        <div class="col-sm-12">
          <div class="form-group">
            <label class="col-sm-2 control-label entering-pd" style="color: red">回复内容:</br>(供派单部门使用)</label>
            <div class="col-sm-10">
                            <textarea id="backDesc" th:field="*{backDesc}" maxlength="3500"
                                      class="form-control"
                                      cols="100"
                                      rows="7" required="required"></textarea>
            </div>
          </div>
        </div>
        <!--按钮-->
<!--        <div class="col-sm-12" style="display: flex;justify-content:center;margin:15px 0px 15px 0px">-->
<!--          <div class="form-group">-->
<!--            <div class="col-sm-3" style="display: flex;justify-content: space-evenly;">-->
<!--              <button type="button" class="btn btn-sm btn-success" onclick="submitHandler()">回复</button>&nbsp;&nbsp;&nbsp;&nbsp;-->
<!--              <button type="button" class="btn btn-sm btn-light" onclick="$.modal.close()">关闭</button>-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
      </div>
    </div>
  </form>
</div>

<th:block th:include="include :: footer"/>
<script>
  var prefix = ctx + "system/mTelWF";

  function submitHandler(index) {
    //根据当前登录用户的角色决定由哪个部门审查
    var stepRoles = "210,240,260,290,310,340";
    var crtRole = $("#crtUserRole").val();
    if (stepRoles.indexOf(crtRole) > -1) {
      $("#crtStepId").val("800");
      $("#crtStepName").val("待市级部门审查");
    } else { //三级不驱动流程
      $("#crtStepId").val("400");
      $("#crtStepName").val("待区县部门审查");
    }

    if ($.validate.form()) {
      let url = prefix + "/cmnFile/dlReplyS";
      let data = $('#form-user-add').serializeArray();
      $.ajax({
        url: url,
        data: data,
        type: 'POST',
        success: function (data) {
          if(data.msg == '操作成功')
            passOrNot(1);//审核同意
        }
      })
    }
  }

  //审核
  function passOrNot(flag){
    var act = parseInt(flag);
    if(act<1){
      if($("#txtReason").val().length<1){
        $.modal.alertWarning("请输入不通过理由");
        return false;
      }
      $("#opinion").val("不同意");
    }
    else{
      if($("#opinion").val().length<1)
        $("#opinion").val("同意");
    }
    //根据当前登录用户的角色决定由哪个部门审查
    var crtPro = $("#setProId").val();//工单类型
    var sortCode = $('#sortCode').val();
    var crtRole = $("#crtUserRole").val();
    var stepRoles = "210,240,260,290,310,340";
    if(stepRoles.indexOf(crtRole) > -1){//市级
      if ("11" != sortCode) {
        if (act < 1)
          $('#backState').val(12);
        else
          $('#backState').val(11);
      }else{
        //主办
        if("11" != crtPro.toString()){
          if(act<1){
            $('#backState').val(12);
            $("#crtStepId").val("801");
            $("#crtStepName").val("市级不通过");
          }
          else{
            $('#backState').val(11);
            $("#crtStepId").val("810");
            $("#crtStepName").val("待效能办审查");
          }
        }
        else{//11 普通工单
          if(act<1){
            $('#backState').val(12);
            $("#crtStepId").val("801");
            $("#crtStepName").val("市级不通过");
          }
          else{
            $('#backState').val(11);
            $("#crtStepId").val("810");
            $("#crtStepName").val("待审定结果");
          }
        }
      }
    }
    else{
      if(act<1){
        $("#backState").val(12);
      }
      else{
        $("#backState").val(11);
      }
    }
    if ($.validate.form()) {
      let url = prefix + "/cmnFile/dlChkReply";
      let data = $('#form-user-add').serializeArray();
      $.ajax({
        url: url,
        data: data,
        type: 'POST',
        success: function (data) {
          $.modal.msgSuccess(data.msg);
          $.modal.close();
          refreshNotSignList();
        }
      })
    }
  }

  // 刷新待签收列表
  function refreshNotSignList() {
    var navFrame = $('.NAP_iframe[data-id="/system/mTelWF/cmnFile/muSignNot"]', parent.document)[0];
    navFrame.contentWindow.$.table.refresh();
  }


</script>
</body>
</html>

